/**
 * 
 */
package com.googlecode.pcapj.bridj;

import org.bridj.Pointer;
import org.bridj.StructObject;
import org.bridj.ann.Array;
import org.bridj.ann.Field;

/**
	struct in6_addr {
		uint8_t  s6_addr[16];   // IPv6 アドレス
	};
 */
public class in6_addr extends StructObject {
    public in6_addr() { super(); }
    public in6_addr(Pointer<? extends StructObject> pointer) { super(pointer); }

    @Array({16})
    @Field(0)
    public Pointer<Byte> s6_addr() {
            return this.io.getPointerField(this, 0);
    }
    public byte[] getBytes(){
    	return s6_addr().getBytes();
    }
	/* (non-Javadoc)
	 * @see org.bridj.StructObject#toString()
	 */
	@Override
	public String toString() {
		StringBuffer stringBuffer = new StringBuffer();
		byte[] addr = getBytes();
		for (int i = 0; i < addr.length; i+=2) {
			if(i != 0){
				stringBuffer.append(":");
			}
			if(addr[i] != 0){
				stringBuffer.append(Integer.toHexString(0xff & addr[i]));
				if((addr[i+1] & 0xf0) == 0){
					stringBuffer.append("0");
				}
			}
			stringBuffer.append(Integer.toHexString(0xff & addr[i+1]));
		}
		return stringBuffer.toString();
	}
    
}
